const baseURL = "http://localhost:4000"
function http({
    url,
    method,
    data
}){
    return new Promise((resolve,reject)=>{
        console.log(baseURL+url);
        wx.request({
            url: baseURL+url,
            method, 
            data,
            success: (res)=>{
                // success
                // console.log(res.statusCode);
                // console.log(res.data.code);
                if(res.statusCode==200 && res.data.code==200){
                    resolve(res);
                }else{
                    wx.showToast({
                        title: '无法连接网络',
                        icon: 'none'
                    })
                    throw new Error("网络异常");
                }
            },
            fail: (res)=> {
                // fail
                reject(res)
                wx.showToast({
                    title: '无法连接网络',
                    icon: 'none'
                })
                throw new Error("网络异常");
            }
        })
    })
}
module.exports = http;